package com.wang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Classname MyWebMvcConfig
 * @Description TODO
 * @Date 2024/5/17 10:56
 * @Created by pc
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    // 处理
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/res/**")
                .addResourceLocations("classpath:/META-INF/resources/",
                        "classpath:/resources/",
                        "classpath:/static/",
                        "classpath:/public/",
                        "file:E:/resources/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 访问某个路径自动跳转到 那个视图
        registry.addViewController("/").setViewName("forward:home.html");
        // 设置优先级最高
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
